package com.mxpio.erp.workshop.controller;

import com.mxpio.erp.common.workshop.entity.ManufactureOrderRouteFixture;
import com.mxpio.erp.common.workshop.service.ManufactureOrderRouteFixtureService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.query.Criteria;
import com.mxpioframework.jpa.query.Operator;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.util.List;

@Tag(name = "ManufactureOrderRouteFixtureController", description = "生产订单工艺路线-工装夹具接口")
@RestController
@RequestMapping("/erp/workshop/moroute/fixture/")
public class ManufactureOrderRouteFixtureController {

	@Autowired
	private ManufactureOrderRouteFixtureService service;
    

    @GetMapping("list")
    @Operation(summary = "生产订单工艺路线-工装夹具列表", description = "获取生产订单工艺路线-工装夹具订单列表（无分页）", method = "GET")
    public Result<List<ManufactureOrderRouteFixture>> list(@Parameter(description="查询参数") Criteria criteria) throws UnsupportedEncodingException {
        List<ManufactureOrderRouteFixture> manufactureOrderItems = service.list(ManufactureOrderRouteFixture.class, criteria);
        return Result.OK(manufactureOrderItems);
    }

    @GetMapping("page")
    @Operation(summary = "生产订单工艺路线-工装夹具列表", description = "获取生产订单工艺路线-工装夹具列表（分页）", method = "GET")
    public Result<Page<ManufactureOrderRouteFixture>> page(@Parameter(description="查询参数") Criteria criteria, @Parameter(description="每页条数")Integer pageSize, @Parameter(description="页号")Integer pageNo) throws UnsupportedEncodingException {
        Pageable page = PageRequest.of(pageNo-1, pageSize);
        Page<ManufactureOrderRouteFixture> manufactureOrderItems = service.listPage(ManufactureOrderRouteFixture.class, page, criteria);
        return Result.OK(manufactureOrderItems);
    }
    @GetMapping("list/{orderRoutProcId}")
    @Operation(summary = "根据orderRoutProcId获取生产订单工艺路线-工装夹具", description = "根据orderRoutProcId获取生产订单工艺路线-工装夹具", method = "GET")
    public Result<List<ManufactureOrderRouteFixture>> getById(@Parameter(description="业务单号") @PathVariable(name = "orderRoutProcId", required = true) String orderRoutProcId) {
        Criteria criteria = Criteria.create();
        criteria.addCriterion("orderRoutProcId", Operator.EQ,orderRoutProcId);
        List<ManufactureOrderRouteFixture> manufactureOrderItem = service.list(ManufactureOrderRouteFixture.class,criteria );
        return Result.OK(manufactureOrderItem);
    }



    @RequestMapping("save")
    @Operation(summary = "更新生产订单工艺路线-工装夹具", description = "更新生产订单工艺路线-工装夹具")
    public Result<List<ManufactureOrderRouteFixture>> save(@RequestBody List<ManufactureOrderRouteFixture> manufactureOrderRouteFixtureList) {
        service.save(manufactureOrderRouteFixtureList);
        return Result.OK(manufactureOrderRouteFixtureList);
    }

}
